
class main():
    def __init__(self,parent):
        self.dh = parent.dh
        
    def credit_account(self,account_number,amount,name='Gift Card'):
        if account_number in self.dh.store_credit_dict.keys():
            account = self.dh.store_credit_dict[account_number]
            account_amount = float(account[1])
            account_amount += float(amount)
            self.dh.store_credit_dict[account_number] = [name,'%.2f' % account_amount]
            self.dh.save_store_credit()
            
    def debit_account(self,account_number,amount,name='Gift Card'):
        amount = float(amount)
        if account_number in self.dh.store_credit_dict.keys():
            account = self.dh.store_credit_dict[account_number]
            old_balance = float(account[1])
            name = account[0]
            if old_balance > amount:
                new_balance = old_balance - amount
                retval = amount
            elif old_balance <= amount:
                new_balance = 0
                retval = old_balance
            self.dh.store_credit_dict[account_number] = [name,'%.2f' % new_balance]
            self.dh.save_store_credit()
        else:
            retval = 0    
        return(retval)
